<?php

namespace Database\Seeders;

use App\Models\Category\CategoryModule;
use Illuminate\Database\Seeder;
use Illuminate\Support\Facades\DB;

class CategoryModuleSeeder extends Seeder
{
    /**
     * Run the database seeds.
     */
    public function run(): void
    {
        $category_modules = DB::connection('rjmysql')->table('category_modules')->get()->toArray();
        $category_modules = json_decode(json_encode($category_modules), true);

        foreach ($category_modules as $categoryData) {
            CategoryModule::updateOrCreate(
                ['id' => $categoryData['id']],
                $categoryData
            );
        }

        $this->command->info('书籍模块数据填充完成！');
    }
}
